package com.wedo.mall.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.e.library.activity.EActivity;
import com.e.library.adapter.Adapter;
import com.e.library.listener.EListener;
import com.wedo.mall.R;
import com.wedo.mall.activity.goods.GoodsDetailActivity;
import com.wedo.mall.entity.Goods;
import com.wedo.mall.util.WUrl;

import java.util.List;

/**
 * Created by e on 2017/7/9.
 */

public class SimilarAdapter extends Adapter<Goods> {

    private String goods_price;

    public SimilarAdapter(Context context, List<Goods> datas) {
        super(context, datas);
        goods_price = context.getResources().getString(R.string.goods_price);
    }

    @Override
    protected int layout() {
        return R.layout.item_goods_similar;
    }

    @Override
    protected void bind(EHolder holder, Goods goods, int position) {

        ImageView iv_img = holder.find(R.id.iv_img);
        ImageView iv_auth = holder.find(R.id.iv_auth);
        TextView tv_name = holder.find(R.id.tv_name);
        TextView tv_price = holder.find(R.id.tv_price);

        iv_auth.setVisibility(goods.auth()?View.VISIBLE:View.INVISIBLE);
        tv_name.setText(goods.goods_name);
        tv_price.setText(String.format(goods_price, goods.fixPrice()));
        String img = WUrl.url(goods.goods_image);
        Glide.with(mContext).load(img).error(R.drawable.place_holder_goods).placeholder(R.drawable.place_holder_goods).diskCacheStrategy(DiskCacheStrategy.ALL).into(iv_img);
    }

    public void listener(final EActivity activity){
        onItemClickListener = new EListener<Goods>() {
            @Override
            public void onInvoked(View view, Goods data, int position) {
                GoodsDetailActivity.toDetail(activity,data.id);
            }
        };
    }
}
